package com.oscar.ehome.view.pageview.adapter;

import android.content.Context;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.oscar.ehome.R;

import com.oscar.ehome.bean.pagebean.BaoDanKehuBean;


import java.util.List;

/**
 * Created by juxing
 * author: SunHaoZhao
 * date: On 2018/3/28
 */

public class BaoDanKeHuAdapter extends BaseAdapter {


    private List<BaoDanKehuBean.kehuxinxi> list;
    private LayoutInflater mInflater;
    private Context mContext = null;

    int size = 0;

    public BaoDanKeHuAdapter(Context context, List<BaoDanKehuBean.kehuxinxi> list) {
        this.mContext = context;
        this.list = list;

        mInflater = LayoutInflater.from(context);
    }

    public void setLists(List<BaoDanKehuBean.kehuxinxi> list) {
        this.list = list;

        notifyDataSetChanged();
    }


    @Override
    public int getCount() {

        size = list.size();
        return size;
    }

    @Override
    public Object getItem(int position) {

        return list.get(position);

    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        BaoDanKeHuAdapter.ViewHolder holder;
        if (convertView == null) {
            convertView = mInflater.inflate(R.layout.baodankehuitem, null);
            holder = new BaoDanKeHuAdapter.ViewHolder();
            holder.kehuname =  convertView.findViewById(R.id.kehuname);
            holder.kehubeizhu=  convertView.findViewById(R.id.kehubeizhu);
            holder.kehuxingbie =  convertView.findViewById(R.id.kehuxingbie);
            holder.baodannum = convertView.findViewById(R.id.baodanshuliang);
            holder.xuqitixing =  convertView.findViewById(R.id.xuqitixing);
            convertView.setTag(holder); //
        } else {
            holder = (BaoDanKeHuAdapter.ViewHolder) convertView.getTag(); //
        }


        holder.kehuname.setText(list.get(position).getName());
        if(list.get(position).getRemarks()!=null&&!list.get(position).getRemarks().equals("")){
            holder.kehubeizhu.setVisibility(View.VISIBLE);
            holder.kehubeizhu.setText(list.get(position).getRemarks());
        }else{
            holder.kehubeizhu.setVisibility(View.GONE);
        }

      holder.baodannum.setText(list.get(position).getPolicySheetCount()+"");
        int jiating = list.get(position).getIsFamily();
        String xingbie = list.get(position).getSex();
        if (jiating == 1) {
            holder.kehuxingbie.setImageResource(R.mipmap.jiating);
        } else {
            if (xingbie.equals("1")) {
                holder.kehuxingbie.setImageResource(R.mipmap.kehunan);
            } else {
                holder.kehuxingbie.setImageResource(R.mipmap.kehunv);
            }
        }
        if (list.get(position).getIsExpired() <1) {
            holder.xuqitixing.setVisibility(View.GONE);
        } else {
            holder.xuqitixing.setVisibility(View.VISIBLE);
        }
        return convertView;
    }

    class ViewHolder {
        TextView kehuname;
        TextView kehubeizhu;
        ImageView kehuxingbie;
        TextView baodannum;
        ImageView xuqitixing;

    }

}
